package com.novell.sasl.client;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Iterator;
import org.apache.harmony.javax.security.sasl.SaslException;

class DirectiveList
{
  private static final int STATE_LOOKING_FOR_FIRST_DIRECTIVE = 1;
  private static final int STATE_LOOKING_FOR_DIRECTIVE = 2;
  private static final int STATE_SCANNING_NAME = 3;
  private static final int STATE_LOOKING_FOR_EQUALS = 4;
  private static final int STATE_LOOKING_FOR_VALUE = 5;
  private static final int STATE_LOOKING_FOR_COMMA = 6;
  private static final int STATE_SCANNING_QUOTED_STRING_VALUE = 7;
  private static final int STATE_SCANNING_TOKEN_VALUE = 8;
  private static final int STATE_NO_UTF8_SUPPORT = 9;
  private int m_curPos = 0;
  private int m_errorPos = -1;
  private String m_directives;
  private int m_state = 1;
  private ArrayList m_directiveList = new ArrayList(10);
  private String m_curName;
  private int m_scanStart = 0;

  DirectiveList(byte[] paramArrayOfByte)
  {
    try
    {
      this.m_directives = new String(paramArrayOfByte, "UTF-8");
    }
    catch (UnsupportedEncodingException localUnsupportedEncodingException)
    {
      this.m_state = 9;
    }
  }

  void parseDirectives()
    throws SaslException
  {
    int j = 0;
    boolean bool = false;
    String str = "<no name>";
    if (this.m_state == 9)
      throw new SaslException("No UTF-8 support on platform");
    int i = 0;
    while (this.m_curPos < this.m_directives.length())
    {
      char c = this.m_directives.charAt(this.m_curPos);
      switch (this.m_state)
      {
      case 1:
      case 2:
        if (!isWhiteSpace(c))
          if (isValidTokenChar(c))
          {
            this.m_scanStart = this.m_curPos;
            this.m_state = 3;
          }
          else
          {
            this.m_errorPos = this.m_curPos;
            throw new SaslException("Parse error: Invalid name character");
          }
        break;
      case 3:
        if (!isValidTokenChar(c))
          if (isWhiteSpace(c))
          {
            str = this.m_directives.substring(this.m_scanStart, this.m_curPos);
            this.m_state = 4;
          }
          else if ('=' == c)
          {
            str = this.m_directives.substring(this.m_scanStart, this.m_curPos);
            this.m_state = 5;
          }
          else
          {
            this.m_errorPos = this.m_curPos;
            throw new SaslException("Parse error: Invalid name character");
          }
        break;
      case 4:
        if (!isWhiteSpace(c))
          if ('=' == c)
          {
            this.m_state = 5;
          }
          else
          {
            this.m_errorPos = this.m_curPos;
            throw new SaslException("Parse error: Expected equals sign '='.");
          }
        break;
      case 5:
        if (!isWhiteSpace(c))
          if ('"' == c)
          {
            this.m_scanStart = (this.m_curPos + 1);
            this.m_state = 7;
          }
          else if (isValidTokenChar(c))
          {
            this.m_scanStart = this.m_curPos;
            this.m_state = 8;
          }
          else
          {
            this.m_errorPos = this.m_curPos;
            throw new SaslException("Parse error: Unexpected character");
          }
        break;
      case 8:
        if (!isValidTokenChar(c))
          if (isWhiteSpace(c))
          {
            addDirective(str, false);
            this.m_state = 6;
          }
          else if (',' == c)
          {
            addDirective(str, false);
            this.m_state = 2;
          }
          else
          {
            this.m_errorPos = this.m_curPos;
            throw new SaslException("Parse error: Invalid value character");
          }
        break;
      case 7:
        if ('\\' == c)
          bool = true;
        if (('"' == c) && (92 != i))
        {
          addDirective(str, bool);
          bool = false;
          this.m_state = 6;
        }
        break;
      case 6:
        if (!isWhiteSpace(c))
          if (c == ',')
          {
            this.m_state = 2;
          }
          else
          {
            this.m_errorPos = this.m_curPos;
            throw new SaslException("Parse error: Expected a comma.");
          }
        break;
      }
      if (j != 0)
        break;
      i = c;
      this.m_curPos += 1;
    }
    if (j == 0)
      switch (this.m_state)
      {
      case 8:
        addDirective(str, false);
        break;
      case 1:
      case 6:
        break;
      case 2:
        throw new SaslException("Parse error: Trailing comma.");
      case 3:
      case 4:
      case 5:
        throw new SaslException("Parse error: Missing value.");
      case 7:
        throw new SaslException("Parse error: Missing closing quote.");
      }
  }

  boolean isValidTokenChar(char paramChar)
  {
    return ((paramChar < 0) || (paramChar > ' ')) && ((paramChar < ':') || (paramChar > '@')) && ((paramChar < '[') || (paramChar > ']')) && (',' != paramChar) && ('%' != paramChar) && ('(' != paramChar) && (')' != paramChar) && ('{' != paramChar) && ('}' != paramChar) && ('' != paramChar);
  }

  boolean isWhiteSpace(char paramChar)
  {
    return ('\t' == paramChar) || ('\n' == paramChar) || ('\r' == paramChar) || (' ' == paramChar);
  }

  void addDirective(String paramString, boolean paramBoolean)
  {
    String str;
    if (!paramBoolean)
    {
      str = this.m_directives.substring(this.m_scanStart, this.m_curPos);
    }
    else
    {
      StringBuffer localStringBuffer = new StringBuffer(this.m_curPos - this.m_scanStart);
      int j = 0;
      for (int i = this.m_scanStart; i < this.m_curPos; i++)
      {
        int k;
        if ('\\' == (k = this.m_directives.charAt(i)))
          i++;
        localStringBuffer.setCharAt(j, this.m_directives.charAt(i));
        j++;
      }
      str = new String(localStringBuffer);
    }
    int m;
    if (this.m_state == 7)
      m = 1;
    else
      m = 2;
    this.m_directiveList.add(new ParsedDirective(paramString, str, m));
  }

  Iterator getIterator()
  {
    return this.m_directiveList.iterator();
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     com.novell.sasl.client.DirectiveList
 * JD-Core Version:    0.6.1
 */